package com.lagou;

import com.lagou.bean.Homework;
import com.lagou.repository.HomeworkRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class MongoRepositoryMain {
    public static void main(String[] args) {
        ApplicationContext  applicationContext = SpringApplication.run(MongoRepositoryMain.class,args);
        HomeworkRepository descriptionRepository = applicationContext.getBean(HomeworkRepository.class);
        //------------------------------插入数据-------------------------------
        List<Homework> homeworkArrayList = new ArrayList<Homework>();
        for (int i = 0; i < 100; i++) {
            Homework homework = new Homework();
            homework.setName("陈浩天"+i+"号");
            homework.setId(i);
            homework.setAge(i);
            homework.setDescription("这是我作业插入的第"+i+"条数据!");
            homeworkArrayList.add(homework);
        }
        descriptionRepository.saveAll(homeworkArrayList);
        //------------------------------------查询---------------------------
        List<Homework> list = descriptionRepository.findAll();
        for (Homework desc : list) {
            System.out.println(desc);
        }
    }
}
